import {
  queryDataType,
  addDataType,
  removeDataType,
  updateDataType,
  queryListForType,
  datatypewordreladd,
} from '@/services/sensitiveData/dataType';

export default {
  namespace: 'dataType',

  state: {
    // 列表数据
    data: {
      dataList: [],
      // pageNum: 0,
      // pageSize: 0,
      // totalCount: 0,
    },
    queryForm: {},
    dataqueryListForType: [],
  },

  effects: {
    *queryList({ payload }, { call, put }) {
      const response = yield call(queryDataType, payload);
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *add({ payload, callback }, { call, put }) {
      const response = yield call(addDataType, payload);
      yield put({
        type: 'saveadd',
        payload: response,
      });
      if (callback) callback(response);
    },
    *remove({ payload, callback }, { call, put }) {
      const response = yield call(removeDataType, payload);
      yield put({
        type: 'saveremove',
        payload: response,
      });
      if (callback) callback(response);
    },
    *update({ payload, callback }, { call, put }) {
      const response = yield call(updateDataType, payload);
      yield put({
        type: 'saveupdate',
        payload: response,
      });
      if (callback) callback(response);
    },
    *queryListForType({ payload }, { call, put }) {
      const response = yield call(queryListForType, payload);
      yield put({
        type: 'savequeryListForType',
        payload: response.data ? response.data.dataList || [] : [],
      });
    },
    *datatypewordreladd({ payload, callback }, { call, put }) {
      const response = yield call(datatypewordreladd, payload);
      return response;
    },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: { dataList: action.payload.data },
        // data: action.payload,
      };
    },
    savequeryListForType(state, { payload }) {
      return {
        ...state,
        dataqueryListForType: payload,
      };
    },
  },
};
